#! /bin/sh
#
# gen_dev dev4 vars.src vars
#
# Generate an overlay config for devNNN from vars.src and write to vars
#

NAME=$1
TEMPLATE=$2
VARFILE=$3

## Allocate some ports per node
##   .
##   .7 - http
NODE="$NAME@127.0.0.1"

NUMBER=${NAME##dev}
BASE=$((10000 + 10 * $NUMBER))
YZSOLRJMXPORT=$(($BASE + 3))
YZSOLRPORT=$(($BASE + 4))
CM_PORT=$(($BASE + 6))
PBPORT=$(($BASE + 7))
WEBPORT=$(($BASE + 8))
HANDOFFPORT=$(($BASE + 9))

echo "Generating $NAME - node='$NODE' yzsolrjmx=$YZSOLRJMXPORT yzsolr=$YZSOLRPORT pbc=$PBPORT http=$WEBPORT handoff=$HANDOFFPORT"
sed -e "s/@NODE@/$NODE/" \
    -e "s/@YZSOLRJMXPORT@/$YZSOLRJMXPORT/" \
    -e "s/@YZSOLRPORT@/$YZSOLRPORT/" \
    -e "s/@PBPORT@/$PBPORT/" \
    -e "s/@WEBPORT@/$WEBPORT/" \
	-e "s/@CM_PORT@/$CM_PORT/" \
    -e "s/@HANDOFFPORT@/$HANDOFFPORT/" < $TEMPLATE > $VARFILE
